﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using SRBInterface;
using SRBPublicFunc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SRB.Tg.Model
{
    /// <summary>
    /// 承台
    /// </summary>
    public class PileCapOld : MemberBase
    {
        public double Length, Width, Height;
        List<double> ArrAlongW, ArrAlongL, ArrAlongH;
        eRebarDia _N1Dia; eRebarDia _N2Dia; eRebarDia _N3Dia; eRebarDia _N4Dia;
        /// <summary>
        /// 承台，单位毫米。
        /// </summary>
        /// <param name="l"></param>
        /// <param name="w"></param>
        /// <param name="h"></param>
        /// <param name="cover"></param>
        public PileCapOld(double l,double w, double h,double cover,eRebarDia N1Dia,eRebarDia N2Dia,eRebarDia N3Dia, eRebarDia N4Dia)// 
        {
            Length = l;
            Width = w;
            Height = h;
            CoverThk = cover;
            _N1Dia = N1Dia;
            _N2Dia = N2Dia;
            _N3Dia = N3Dia;
            _N4Dia = N4Dia;

    






            #region 配置钢筋
            // 配筋外径12mm,内径10mm

            //in_dia = 10;
            // N1
            double NetWidthForN1 = Length - 2 * CoverThk -2*GeneralRebar.outerDia[N2Dia]-GeneralRebar.outerDia[N1Dia];
            List<double> N1Arr = RebarArrangement.ArrangeRebar(NetWidthForN1, 150);
            int NumOfN1= N1Arr.Count+1;
            GeneralRebar N1 = new GeneralRebar("N1", eRebarClass.T, N1Dia, RebarEnd.En90, RebarEnd.En90);
            //N1.LineSegmentList.Add(NetWidthForN1);
            N1.LineSegmentList.Add(Width - 2 * CoverThk - GeneralRebar.outerDia[N1Dia]);
            //N1.LineSegmentList.Add(NetWidthForN1);
            //N1.BendList.Add(RebarBend.B90);
            //N1.BendList.Add(RebarBend.B90);
            rebarList.Add(new Tuple<RebarBase, int>(N1, NumOfN1));
            // N2
            double NetWidthForN2 = Width - 2 * CoverThk - 2 * GeneralRebar.outerDia[N1Dia] - GeneralRebar.outerDia[N2Dia];
            List<double> N2Arr = RebarArrangement.ArrangeRebar(NetWidthForN2, 150);
            int NumOfN2 = N2Arr.Count + 1;            
            GeneralRebar N2 = new GeneralRebar("N2", eRebarClass.Y, N2Dia, RebarEnd.En90, RebarEnd.En90);
            //N2.LineSegmentList.Add(NetWidthForN2);
            N2.LineSegmentList.Add(Length - 2 * CoverThk - GeneralRebar.outerDia[N2Dia]);
            //N2.LineSegmentList.Add(NetWidthForN2);
            //N2.BendList.Add(RebarBend.B90);
            //N2.BendList.Add(RebarBend.B90);
            rebarList.Add(new Tuple<RebarBase, int>(N2, NumOfN2));
          
            //N3 *2            
            GeneralRebar N3 = new GeneralRebar("N3", eRebarClass.T, N3Dia, RebarEnd.En90, RebarEnd.En90);
            //N3.LineSegmentList.Add(NetWidthForN1);
            N3.LineSegmentList.Add(Width - 2 * CoverThk - GeneralRebar.outerDia[N1Dia]);
            //N3.LineSegmentList.Add(NetWidthForN1);
            //N3.BendList.Add(RebarBend.B90);
            //N3.BendList.Add(RebarBend.B90);
            rebarList.Add(new Tuple<RebarBase, int>(N3, NumOfN1));
            //N4 *2            
            GeneralRebar N4 = new GeneralRebar("N4", eRebarClass.T, N4Dia, RebarEnd.En90, RebarEnd.En90);
            //N4.LineSegmentList.Add(NetWidthForN2);
            N4.LineSegmentList.Add(Length - 2 * CoverThk - GeneralRebar.outerDia[N2Dia]);
            //N4.LineSegmentList.Add(NetWidthForN2);
            //N4.BendList.Add(RebarBend.B90);
            //N4.BendList.Add(RebarBend.B90);
            rebarList.Add(new Tuple<RebarBase, int>(N4, NumOfN2));

            //N5a 默认D16 ,竖向面筋           
            int NumOfN5a = NumOfN2 * 2;
            GeneralRebar N5a = new GeneralRebar("N5a", eRebarClass.Y, eRebarDia.D16,RebarEnd.En90, RebarEnd.En90);
            N5a.LineSegmentList.Add(Height - CoverThk - 100 + GeneralRebar.outerDia[eRebarDia.D16]);
            rebarList.Add(new Tuple<RebarBase, int>(N5a, NumOfN5a));
            //N5b 默认D16 ,竖向面筋  
            int NumOfN5b = NumOfN1 * 2;
            GeneralRebar N5b = new GeneralRebar("N5b", eRebarClass.Y, eRebarDia.D16, RebarEnd.En90, RebarEnd.En90);
            N5b.LineSegmentList.Add(Height - CoverThk - 100 - GeneralRebar.outerDia[N1Dia] - GeneralRebar.outerDia[N3Dia] + GeneralRebar.outerDia[eRebarDia.D16]);
            rebarList.Add(new Tuple<RebarBase, int>(N5b, NumOfN5b));
            //N6a  默认D16,水平面筋  ,与W平行            
            int NumOfN6 = (RebarArrangement.ArrangeRebar(Height -  CoverThk-100-180, 150).Count + 1)*2;
            GeneralRebar N6a = new GeneralRebar("N6a", eRebarClass.Y, eRebarDia.D16, RebarEnd.En90, RebarEnd.En90);
            N6a.LineSegmentList.Add(N2Arr.Sum()+GeneralRebar.outerDia[N2Dia]+GeneralRebar.outerDia[eRebarDia.D16]);
            rebarList.Add(new Tuple<RebarBase, int>(N6a, NumOfN6));
            //N6b 默认D16 ,水平面筋  ,与L平行
            GeneralRebar N6b = new GeneralRebar("N6b", eRebarClass.Y, eRebarDia.D16, RebarEnd.En90, RebarEnd.En90);
            N6b.LineSegmentList.Add(N1Arr.Sum() + GeneralRebar.outerDia[N1Dia] + GeneralRebar.outerDia[eRebarDia.D16]);
            rebarList.Add(new Tuple<RebarBase, int>(N6b, NumOfN6));

            ////N7   *2
            //double N7L = Length - 2 * CoverThk - GeneralRebar.outerDia[N4Dia] - 2 * GeneralRebar.outerDia[eRebarDia.D16];
            //int NumOfN7 = RebarArrangement.ArrangeRebar(Height - 2 * CoverThk - GeneralRebar.outerDia[eRebarDia.D16] * 4 - GeneralRebar.outerDia[N4Dia], 150).Count + 1;
            //GeneralRebar N7 = new GeneralRebar("N7", eRebarClass.T, N4Dia, RebarEnd.En90, RebarEnd.En90);
            //N7.LineSegmentList.Add(N7L);
            //rebarList.Add(new Tuple<RebarBase, int>(N7, NumOfN7));

            ////N8 
            //double N8L = Height - 2 * CoverThk - GeneralRebar.outerDia[N2Dia] - 2 * GeneralRebar.outerDia[eRebarDia.D16];
            //int NumOfN8 = RebarArrangement.ArrangeRebar(Length - 2 * CoverThk - GeneralRebar.outerDia[eRebarDia.D16] * 4 - GeneralRebar.outerDia[N2Dia], 150).Count + 1;
            //GeneralRebar N8 = new GeneralRebar("N8", eRebarClass.T, N2Dia, RebarEnd.En90, RebarEnd.En90);
            //N8.LineSegmentList.Add(N8L);
            //rebarList.Add(new Tuple<RebarBase, int>(N8, NumOfN8));

            ArrAlongW = RebarArrangement.ArrangeRebar(NetWidthForN2, 150);
            ArrAlongL = RebarArrangement.ArrangeRebar(NetWidthForN1, 150);
            ArrAlongH = RebarArrangement.ArrangeRebar(Height - CoverThk - 100 - 180, 150);
            #endregion



        }
      
        /// <summary>
        /// 渲染图形
        /// </summary>
        /// <param name="scale"></param>
        public void DrawingPileCap(Database db, int OverAllScale)
        {
            #region 绘制图形
            Extents2d ExtEF, ExtAB, ExtCD, ExtDetail;
            Point2d RefPtAB, RefPtCD, RefPtEF, RefPtDetail;

            RefPtAB = Point2d.Origin;
            RefPtCD = RefPtAB.C2D(420 * OverAllScale);
            RefPtEF = RefPtAB.C2D(0, -297 * OverAllScale);
            RefPtDetail = RefPtEF.C2D(420 * OverAllScale);

            PlotElevationAB(ref db, out ExtAB, RefPtAB, OverAllScale);
            BaseShapePloter.RenderEntity(db, ExtAB.ConvertPL());

            PlotElevationCD(ref db, out ExtCD, RefPtCD, OverAllScale);
            BaseShapePloter.RenderEntity(db, ExtCD.ConvertPL());

            PlotElevationEF(ref db, out ExtEF, RefPtEF, OverAllScale);
            BaseShapePloter.RenderEntity(db, ExtEF.ConvertPL());

            RendeDetail(ref db, RefPtDetail, out ExtDetail);
            BaseShapePloter.RenderEntity(db, ExtDetail.ConvertPL());
            #endregion
            #region 模型空间到布局空间投影处理
            Common.CreateLayoutAuto(db, "PileCapDrawing", ExtAB, ExtCD, ExtEF, ExtDetail,
             RefPtAB, RefPtCD, RefPtEF, RefPtDetail, 15, 5, OverAllScale);
            #endregion
        }

        /// <summary>
        /// 绘制AB
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="scale"></param>
        public void PlotElevationAB(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            TextPloter.PrintScaleText(db, insertPoint.C2D(-Width / 4, 0), "1/2 SECTION A-A", string.Format("(1:{0:G})", scale), ref ext, scale, Extensions.curFont);
            TextPloter.PrintScaleText(db, insertPoint.C2D(Width / 4, 0), "1/2 SECTION B-B", string.Format("(1:{0:G})", scale), ref ext, scale, Extensions.curFont);

            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -25 * scale);

            PolylinePloter.AddPloy4(db, ref ext, M1, 0.5 * Width, 0.5 * Width, Height);
            List<Point3d> leftPts, topPts;   //左边点集合
            List<Point3d> topPtsR = new List<Point3d>(), rightPtsR = new List<Point3d>(); //右边点集合

            #region 网格
            double out_dia = GeneralRebar.outerDia[_N1Dia];
  
            List<double> ArrAlongWHalf = new List<double>();
            List<double> ArrAlongRWHalf = new List<double>();
            for (int i = 0; i < ArrAlongW.Count / 2; i++)
            {
                ArrAlongWHalf.Add(ArrAlongW[i]);
            }
            for (int i = ArrAlongW.Count / 2; i < ArrAlongW.Count - 1; i++)
            {
                ArrAlongRWHalf.Add(ArrAlongW[i]);
            }
            PolylinePloter.CreateLineGrid(db, M1.C2D(-0.5 * Width + CoverThk + 1.5 * out_dia, -CoverThk - 1.5 * out_dia), ArrAlongH, ArrAlongWHalf,
                ref ext, out_dia, out leftPts, out topPts);

            #endregion
            PolylinePloter.AddLine(db, ref ext, M1.C3D(0,5*scale),M1.C3D(0,-Height-5*scale),"中心线");
            #region 标注
            // 两层左侧标注
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
            //    new List<Point3d>() { M1.C3D(0, -Height), leftPts[0], leftPts[1] }, 20, 90);
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
            //     new List<Point3d>() { leftPts[1], leftPts[leftPts.Count - 2] }, 20, 90, 150);
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
            //    new List<Point3d>() { leftPts[leftPts.Count - 2], leftPts[leftPts.Count - 1], M1.C3D() }, 20, 90);
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk - 5 * scale),
            //    new List<Point3d>() { M1.C3D(0, -Height), M1.C3D() }, 20, 90);
            for (int i = 0; i < leftPts.Count; i++)
            {
                rightPtsR.Add(leftPts[i].C3D(Width));
                PolylinePloter.AddLine(db, ref ext, leftPts[i], new Point3d(M1.X, leftPts[i].Y,0));
            }
            leftPts.Add(M1.C3D(-Width * 0.5, -Height));
            leftPts.Add(M1.C3D(-Width * 0.5));
            leftPts.Sort((x, y) => x.Y.CompareTo(y.Y));
            DimPloter.AddDoubleListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale), leftPts, scale, 90, 150, ArrowDirection.West);

            //上部标注
            double len = 0;
            topPtsR.Add(M1.C3D(len));
            foreach (var item in ArrAlongRWHalf)
            {
                len += item;
                topPtsR.Add(M1.C3D(len));
            }
            topPts.Add(M1.C3D(-Width * 0.5).C3D());
            topPts.Add(M1.C3D());
            topPts.Sort((x, y) => x.X.CompareTo(y.X));

            topPtsR.Add(M1.C3D(Width * 0.5).C3D());
            topPtsR.Sort((x, y) => x.X.CompareTo(y.X));

            DimPloter.AddDoubleListDivHalfDimRotated(db, ref ext, topPts[0].C3D(0, 10 * scale + CoverThk), M1.C3D(), topPts, scale, 0, 150, 2);
            DimPloter.AddDoubleListDivHalfDimRotated(db, ref ext, topPts[0].C3D(0, 10 * scale + CoverThk), M1.C3D(), topPtsR, scale, 0, 150, 0);

            //右侧标注
            //rightPtsR.Add(M1.C3D(Width * 0.5, -Height));
            //rightPtsR.Add(M1.C3D(Width * 0.5));
            rightPtsR.Sort((x, y) => x.Y.CompareTo(y.Y));
            rightPtsR.Sort((a, b) => b.Y.CompareTo(a.Y));
            DimPloter.AddDoubleListDimRotated(db, ref ext, rightPtsR[0].C3D(10 * scale), rightPtsR, scale, 90, 150, ArrowDirection.East);

            #endregion

            #region  E/F标记
            PolylinePloter.AddBJByDirectiong(db, ref ext, M1.C3D(-0.5 * Width - 15 * scale - CoverThk, -10), ArrowDirection.West, "E", scale);
            PolylinePloter.AddBJByDirectiong(db, ref ext, M1.C3D(0.5 * Width + 20 * scale + CoverThk, -10), ArrowDirection.East, "E", scale);

            PolylinePloter.AddBJByDirectiong(db, ref ext, M1.C3D(-0.5 * Width - 15 * scale - CoverThk, -15 * scale), ArrowDirection.West, "F", scale);
            PolylinePloter.AddBJByDirectiong(db, ref ext, M1.C3D(0.5 * Width + 20 * scale + CoverThk, -15 * scale), ArrowDirection.East, "F", scale);
            #endregion

            #region 承台联接柱体
            PolylinePloter.CreateCylindricalSection(db, ref ext, M1.C3D(), Width / (10 * scale), 8, true, scale);
            PolylinePloter.CreateCylindricalSection(db, ref ext, M1.C3D(-Width / 4, -Height), Width / (10 * scale), 8, false, scale);
            PolylinePloter.CreateCylindricalSection(db, ref ext, M1.C3D(Width / 4, -Height), Width / (10 * scale), 8, false, scale);
            #endregion

            #region
            List<Point3d> bottomPtsR = new List<Point3d>();
            for (int i = 0; i < topPtsR.Count; i++)
            {
                bottomPtsR.Add(topPtsR[i].C3D(0, -Height));
            }
            PolylinePloter.CreateRebarPointLine(db, ref ext, eDirection.E_BOTTOM, topPtsR, "3", 2, scale);
            PolylinePloter.CreateRebarPointLine(db, ref ext, eDirection.E_TOP, bottomPtsR, "3", 2, scale);
            //PolylinePloter.CreateRebarPointLine(db, ref ext, eDirection.E_TOP, topPtsR, "3", 2, scale);
            PolylinePloter.CreateRebarPointLine(db, ref ext, eDirection.E_RIGHT, rightPtsR, "7", 2, scale);


            #endregion

        }
        /// <summary>
        /// 绘制CD
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="scale"></param>
        public void PlotElevationCD(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            TextPloter.PrintScaleText(db, insertPoint.C2D(-Length / 2, 0), "1/2 SECTION C-C", string.Format("(1:{0:G})", scale), ref ext, scale, Extensions.curFont);
            TextPloter.PrintScaleText(db, insertPoint.C2D(Length / 4, 0), "1/2 SECTION D-D", string.Format("(1:{0:G})", scale), ref ext, scale, Extensions.curFont);
            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -25 * scale);

            PolylinePloter.AddPloy4(db, ref ext, M1, 0.5 * Length, 0.5 * Length, Height);

            List<Point3d> leftPts, topPts;   //左边点集合
            List<Point3d> topPtsR = new List<Point3d>(), rightPtsR = new List<Point3d>(); //右边点集合

            #region 网格
            double out_dia = GeneralRebar.outerDia[_N4Dia];
            //List<Point3d> leftPts, topPts;
            List<double> ArrAlongLHalf = new List<double>();
            for (int i = 0; i < ArrAlongL.Count / 2; i++)
            {
                ArrAlongLHalf.Add(ArrAlongL[i]);
            }
            //List<Point3d> topPtsR = new List<Point3d>();
            List<double> ArrAlongRLHalf = new List<double>();
            for (int i = ArrAlongL.Count / 2; i < ArrAlongL.Count - 1; i++)
            {
                ArrAlongRLHalf.Add(ArrAlongL[i]);
            }
            PolylinePloter.CreateLineGrid(db, M1.C2D(-0.5 * Length + CoverThk + 1.5 * out_dia, -CoverThk - 1.5 * out_dia), ArrAlongH, ArrAlongLHalf,
                ref ext, out_dia, out leftPts, out topPts);
            #endregion
            PolylinePloter.AddLine(db, ref ext, M1.C3D(0, 5 * scale), M1.C3D(0, -Height - 5 * scale), "中心线");
            #region 标注
            // 两层左侧标注
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
            //    new List<Point3d>() { M1.C3D(0, -Height), leftPts[0], leftPts[1] }, 20, 90);
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
            //     new List<Point3d>() { leftPts[1], leftPts[leftPts.Count - 2] }, 20, 90, 150);
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
            //    new List<Point3d>() { leftPts[leftPts.Count - 2], leftPts[leftPts.Count - 1], M1.C3D() }, 20, 90);
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk - 5 * scale),
            //    new List<Point3d>() { M1.C3D(0, -Height), M1.C3D() }, 20, 90);
            for (int i = 0; i < leftPts.Count; i++)
            {
                rightPtsR.Add(leftPts[i].C3D(Length));
                PolylinePloter.AddLine(db, ref ext, leftPts[i], new Point3d(M1.X, leftPts[i].Y, 0));
            }
            leftPts.Add(M1.C3D(-Length * 0.5, -Height));
            leftPts.Add(M1.C3D(-Length * 0.5));
            leftPts.Sort((x, y) => x.Y.CompareTo(y.Y));
            DimPloter.AddDoubleListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale), leftPts, scale, 90, 150, ArrowDirection.West);

            double len = 0;
            topPtsR.Add(M1.C3D(len));
            foreach (var item in ArrAlongRLHalf)
            {
                len += item;
                topPtsR.Add(M1.C3D(len));
            }
            topPts.Add(M1.C3D(-Length * 0.5).C3D());
            topPts.Add(M1.C3D());
            topPts.Sort((x, y) => x.X.CompareTo(y.X));

            topPtsR.Add(M1.C3D(Length * 0.5).C3D());
            topPtsR.Sort((x, y) => x.X.CompareTo(y.X));

            DimPloter.AddDoubleListDivHalfDimRotated(db, ref ext, topPts[0].C3D(0, 10 * scale + CoverThk), M1.C3D(), topPts, scale, 0, 150, 2);
            DimPloter.AddDoubleListDivHalfDimRotated(db, ref ext, topPts[0].C3D(0, 10 * scale + CoverThk), M1.C3D(), topPtsR, scale, 0, 150, 0);

            //右侧标注
            rightPtsR.Add(M1.C3D(Length * 0.5, -Height));
            rightPtsR.Add(M1.C3D(Length * 0.5));
            rightPtsR.Sort((x, y) => x.Y.CompareTo(y.Y));
            DimPloter.AddDoubleListDimRotated(db, ref ext, rightPtsR[0].C3D(5 * scale), rightPtsR, scale, 90, 150, ArrowDirection.East);

            #endregion


            #region 承台联接柱体
            PolylinePloter.CreateCylindricalSection(db, ref ext, M1.C3D(), Width / (8 * scale), 8, true, scale);
            PolylinePloter.CreateCylindricalSection(db, ref ext, M1.C3D(0, -Height), Width / (8 * scale), 8, false, scale);
            #endregion

        }

        /// <summary>
        /// 绘制EF
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="scale"></param>
        public void PlotElevationEF(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            TextPloter.PrintScaleText(db, insertPoint.C2D(-Width / 4, 0), "1/2 SECTION E-E", string.Format("(1:{0:G})", scale), ref ext, scale, Extensions.curFont);
            TextPloter.PrintScaleText(db, insertPoint.C2D(Width / 4, 0), "1/2 SECTION F-F", string.Format("(1:{0:G})", scale), ref ext, scale, Extensions.curFont);
            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -25 * scale);

            PolylinePloter.AddPloy4(db, ref ext, M1, 0.5 * Width, 0.5 * Width, Length);

            List<Point3d> leftPts, topPts;   //左边点集合
            List<Point3d> topPtsR = new List<Point3d>(), rightPtsR = new List<Point3d>(); //右边点集合

            PolylinePloter.AddLine(db, ref ext, M1.C3D(0, 5 * scale), M1.C3D(0, -Length - 5 * scale), "中心线");
            #region 网格
            //double out_dia = 12;

            //ArrAlongH = RebarArrangement.ArrangeRebar(Height - CoverThk * 2 - 3 * out_dia, 150);
            //List<Point3d> leftPts, topPts;
            List<double> ArrAlongWHalf = new List<double>();
            for (int i = 0; i < ArrAlongW.Count / 2; i++)
            {
                ArrAlongWHalf.Add(ArrAlongW[i]);
            }
            //List<Point3d> topPtsR = new List<Point3d>();
            List<double> ArrAlongRWHalf = new List<double>();
            for (int i = ArrAlongW.Count / 2; i < ArrAlongW.Count - 1; i++)
            {
                ArrAlongRWHalf.Add(ArrAlongW[i]);
            }
            PolylinePloter.CreateLineGrid(db, M1.C2D(-0.5 * Width + CoverThk + 1.5 * GeneralRebar.outerDia[_N1Dia], -CoverThk - 1.5 * GeneralRebar.outerDia[_N1Dia]), ArrAlongL, ArrAlongWHalf,
                ref ext, GeneralRebar.outerDia[_N1Dia], out leftPts, out topPts);
            #endregion

            #region 标注
            // 两层左侧标注
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
            //    new List<Point3d>() { M1.C3D(0, -Length), leftPts[0], leftPts[1] }, 20, 90);
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
            //     new List<Point3d>() { leftPts[1], leftPts[leftPts.Count - 2] }, 20, 90, 150);
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
            //    new List<Point3d>() { leftPts[leftPts.Count - 2], leftPts[leftPts.Count - 1], M1.C3D() }, 20, 90);
            //DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk - 5 * scale),
            //    new List<Point3d>() { M1.C3D(0, -Length), M1.C3D() }, 20, 90);
            for (int i = 0; i < leftPts.Count; i++)
            {
                rightPtsR.Add(leftPts[i].C3D(Width));
                PolylinePloter.AddLine(db, ref ext, leftPts[i], new Point3d(M1.X, leftPts[i].Y, 0));
            }
            leftPts.Add(M1.C3D(-Width * 0.5, -Length));
            leftPts.Add(M1.C3D(-Width * 0.5));
            leftPts.Sort((x, y) => x.Y.CompareTo(y.Y));
            DimPloter.AddDoubleListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale), leftPts, scale, 90, 150, ArrowDirection.West);


            double len = 0;
            topPtsR.Add(M1.C3D(len));
            foreach (var item in ArrAlongRWHalf)
            {
                len += item;
                topPtsR.Add(M1.C3D(len));
            }
            topPts.Add(M1.C3D(-Width * 0.5).C3D());
            topPts.Add(M1.C3D());
            topPts.Sort((x, y) => x.X.CompareTo(y.X));

            topPtsR.Add(M1.C3D(Width * 0.5).C3D());
            topPtsR.Sort((x, y) => x.X.CompareTo(y.X));

            DimPloter.AddDoubleListDivHalfDimRotated(db, ref ext, topPts[0].C3D(0, 10 * scale + CoverThk), M1.C3D(), topPts, scale, 0, 150, 2);
            DimPloter.AddDoubleListDivHalfDimRotated(db, ref ext, topPts[0].C3D(0, 10 * scale + CoverThk), M1.C3D(), topPtsR, scale, 0, 150, 0);


            //右侧标注
            rightPtsR.Add(M1.C3D(Width * 0.5, -Length));
            rightPtsR.Add(M1.C3D(Width * 0.5));
            rightPtsR.Sort((x, y) => x.Y.CompareTo(y.Y));
            DimPloter.AddDoubleListDimRotated(db, ref ext, rightPtsR[0].C3D(5 * scale), rightPtsR, scale, 90, 150, ArrowDirection.East);

            #endregion

            #region  C/D标记
            PolylinePloter.AddBJByDirectiong(db, ref ext, M1.C3D(-Width / 2, 20 * scale), ArrowDirection.North, "C", scale);
            PolylinePloter.AddBJByDirectiong(db, ref ext, M1.C3D(-Width / 2, -Length - 10*scale), ArrowDirection.South, "C", scale);

            PolylinePloter.AddBJByDirectiong(db, ref ext, M1.C3D(0, 20 * scale), ArrowDirection.North, "D", scale);
            PolylinePloter.AddBJByDirectiong(db, ref ext, M1.C3D(0, -Length-10 * scale), ArrowDirection.South, "D", scale);
            #endregion

            #region  A/B标记
            PolylinePloter.AddL2RUpperBJByDirectiong(db, ref ext, M1.C3D(-0.5 * Width - 15 * scale - CoverThk, -Length), ArrowDirection.West, "A", scale);
            PolylinePloter.AddL2RUpperBJByDirectiong(db, ref ext, M1.C3D(0.5 * Width + 15 * scale + CoverThk, -Length), ArrowDirection.East, "A", scale);

            PolylinePloter.AddL2RUpperBJByDirectiong(db, ref ext, M1.C3D(-0.5 * Width - 15 * scale - CoverThk, -Length + 10 * scale), ArrowDirection.West, "B", scale);
            PolylinePloter.AddL2RUpperBJByDirectiong(db, ref ext, M1.C3D(0.5 * Width + 15 * scale + CoverThk, -Length + 10 * scale), ArrowDirection.East, "B", scale);
            #endregion

            #region 
            PolylinePloter.CreateCicleSection(db, ref ext, M1.C3D(0, -Length / 2), Width / (10 * scale), scale);
            PolylinePloter.CreateCicleSection(db, ref ext, M1.C3D(-Width / 4, -Length / 2), Width / (10 * scale), scale, "虚线");
            PolylinePloter.CreateCicleSection(db, ref ext, M1.C3D(Width / 4, -Length / 2), Width / (10 * scale), scale, "虚线");
            #endregion
        }

        /// <summary>
        /// 绘制钢筋
        /// </summary>
        /// <param name="db"></param>
        /// <param name="insertPoint"></param>
        /// <param name="ext"></param>
        public void RendeDetail(ref Database db, Point2d insertPoint, out Extents2d ext, double scale = 50)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            GeneralRebar N1 = (GeneralRebar)rebarList[0].Item1;
            int NumOfN1 = rebarList[0].Item2;

            string LeftMark = "";
            string MidMark = string.Format("{0:G}", N1.LineSegmentList[0]);
            string RightMark = LeftMark;
        
            string RebarInfo = string.Format("{0:G}"+ N1.Diameter.ToString().Replace("D","T"), NumOfN1, Convert.ToInt32(N1.Diameter));
            string RebarTotalLength = string.Format("{0:F0}", N1.TotalLength);

            PolylinePloter.CreateRebarModel(db, ref ext, insertPoint, LeftMark, RightMark, MidMark, RebarInfo, RebarTotalLength,
                1, 3 * scale, 3 * scale, N1.LineSegmentList[0], 180, scale);

            GeneralRebar N3= (GeneralRebar)rebarList[2].Item1;
            int NumOfN3 = rebarList[2].Item2;
            LeftMark = "";
            MidMark = string.Format("{0:G}", N3.LineSegmentList[0]);
            RightMark = LeftMark;
            RebarInfo = string.Format("{0:G}"+ N3.Diameter.ToString().Replace("D", "T"), NumOfN3, Convert.ToInt32(N3.Diameter));
            RebarTotalLength = string.Format("{0:F0}", N3.TotalLength);

            PolylinePloter.CreateRebarModel(db, ref ext, insertPoint.C2D(0, -10 * scale), LeftMark, RightMark, MidMark, RebarInfo, RebarTotalLength,
                3, 3 * scale, 3 * scale, N3.LineSegmentList[0], 180, scale);
            // N2
            GeneralRebar N2 = (GeneralRebar)rebarList[1].Item1;
            int NumOfN2 = rebarList[1].Item2;       
            LeftMark = "";
            MidMark = string.Format("{0:G}", N2.LineSegmentList[0]);
            RightMark = LeftMark;
            RebarInfo = string.Format("{0:G}"+ N2.Diameter.ToString().Replace("D", "T"), NumOfN2, Convert.ToInt32(N2.Diameter));
            RebarTotalLength = string.Format("{0:F0}", N2.TotalLength);

            PolylinePloter.CreateRebarModel(db, ref ext, insertPoint.C2D(0, -20 * scale), LeftMark, RightMark, MidMark, RebarInfo, RebarTotalLength,
                2, 3 * scale, 3 * scale, N2.LineSegmentList[0], 180, scale);

            GeneralRebar N4 = (GeneralRebar)rebarList[3].Item1;
            int NumOfN4 = rebarList[3].Item2;
            LeftMark = "";
            MidMark = string.Format("{0:G}", N4.LineSegmentList[0]);
            RightMark = LeftMark;
            RebarInfo = string.Format("{0:G}" + N4.Diameter.ToString().Replace("D", "T"), NumOfN4, Convert.ToInt32(N4.Diameter));
            RebarTotalLength = string.Format("{0:F0}", N4.TotalLength);

            PolylinePloter.CreateRebarModel(db, ref ext, insertPoint.C2D(0, -30 * scale), LeftMark, RightMark, MidMark, RebarInfo, RebarTotalLength,
                4, 3 * scale, 3 * scale, N4.LineSegmentList[0], 180, scale);

        }

        public override DBObjectCollection Render()
        {
            var f = new DBObjectCollection();

            return f;
        }
    }
}
